You need to enable JavaScript to run this app. JustBasic运行代码出现select/case bad nesting error错误如何解决
优惠活动
大模型
产品
解决方案
定价
更多

JustBasic运行代码出现select/case bad nesting error错误如何解决

错误原因
  • Select Case 语法结构要求起始的Select语句、所有Case分支、结束的End Select必须在同一执行上下文内,不能跨Gosub调用拆分。你当前把Select Case Upper$(Choice$)写在[Menu]模块中,模块执行Return回到主循环后,Select的上下文已经失效,后续[Deposit]、[Withdrawal]、[ShowBalance]模块中的Case语句找不到对应的Select匹配,因此抛出嵌套错误。
  • 额外语法缺陷:[Withdrawal]模块中的If判断没有写对应的End If闭合,也会引发语法报错。
  • 逻辑缺陷:当前主循环的写法会强制按顺序执行菜单、存款、取款、查余额四个模块,不管用户选的是什么选项,就算语法修复也无法实现对应功能。
修复方案

调整代码结构,把Select Case完整逻辑放在主循环中,各子模块仅保留功能实现代码,不要混入Case语句,修正后参考代码如下:

Balance=1000
Print "Banking Menu"
Do
    Gosub [Menu]
    ' Select Case 完整结构放在主循环内
    Select Case Upper$(Choice$)
        Case "A"
            Gosub [Deposit]
        Case "B"
            Gosub [Withdrawal]
        Case "C"
            Gosub [ShowBalance]
        Case "Q"
            ' 退出循环
        Case Else
            Print "Invalid selection, please try again"
    End Select
Loop Until Choice$="Q"
Print "Thanks for using the Banking Application"
End

[Menu]
Print "A. Deposit"
Print "B. Withdrawal"
Print "C. Show Balance"
Print "Q. Quit"
Input "Make Selection: ";Choice$
Return

[Deposit]
Input "Enter Amount to Deposit: ";Dep
If Dep > 0 Then
    Balance=Balance+Dep
Else
    Print "Invalid Amount"
End If
Return

[Withdrawal]
Input "Enter Amount to Withdraw: ";Wdrw
If Wdrw <= 1000 And Wdrw > 0 Then
    Balance=Balance-Wdrw
Else
    Print "Invalid Amount"
End If
Return

[ShowBalance]
Print
Print "*********************************"
Print "*** Account Balance: $";using("####.##",Balance);" ***"
Print "*********************************"
Print
Print "----------------------------"
Return

内容的提问来源于stack exchange,提问作者David T

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 00:54:02