学习qbasic并试图理解我刚写的代码

编程入门 行业动态 更新时间:2024-10-22 23:42:20
本文介绍了学习qbasic并试图理解我刚写的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我遇到了一个问题,告诉我用星星打印一个三角形。 我最终猜测并检查并取出它。

So I had a problem on a hw assignment that told me to print a triangle out of stars. I ended up guessing and checking and pulling out this.

DIM LINES AS INTEGER CLS INPUT "How many lines will your triangle be: ", LINES FOR x = 1 TO LINES PRINT FOR y = 1 TO x PRINT "*"; NEXT y NEXT x END

守则有效,但我不明白怎么做。我已经快速掌握了编程,但嵌套循环让我在大部分时间都感到困惑。我现在很难学习qbasic,但这就是我的学校提供​​的。有人可以解释我刚才写的代码。并帮助我DO和FOR命令。谢谢我,我的硬件非常好,所以我的老师没有帮助。 我尝试了什么: 我猜并检查了代码,现在我很困惑。我只是要求解释。尝试自我解释,但是,没有理解它。

The Code works but I dont understand how. I've picked up programming fast, but nested loops have left me confused most of the time. I now its weird to be learning qbasic but that is what my school offers. Can someone please explain the code I just wrote. And help me with DO, and FOR commands. Thank You I am really far ahead with the HW so my teacher isnt helping. What I have tried: I guess and checked the code and am now confused. An explanation is all im asking for. Tried to self explain but, didnt understand it.

推荐答案

我会在一张纸上开始,因为你只有3个变量,LINES,X,Y 我打算使用符号a< - b表示a的值变为b LINES< - 5作为起点 X< - 1(满分5分) Y< - 1 (超出X等于1) 打印* 第1行,打印一份* X< - 2(满分5分) Y< - 1(X中等于2) 打印* Y< - 2(X中等于2) 打印* 第2行,两个*打印 X< - 3(满分5分) Y< - 1(X中等于3) 打印* Y< - 2(X中等于3) 打印* Y< - 3(超出X等于3) 第3行,3*打印 所以对于我的情况5(线)中的每一行'X',我将使用'Y'来打印该行上的星数 - 等于X星 - 第一行有1星,第二行有2星,第三行有3星,第4行有4星,第5行有5星 btw,在两个循环之间XY即 I would have started on a piece of paper, since you only have 3 variables, LINES, X, Y I'm going to use a notation a <- b means that a becomes the value of b LINES <- 5 as a start point X <- 1 (out of 5) Y <- 1 (out of X which equals 1) Print "*" Line 1, one "*" printed X <- 2 (out of 5) Y <- 1 (out of X which equals 2) Print "*" Y <- 2 (out of X which equals 2) Print "*" Line 2, two "*" printed X <- 3 (out of 5) Y <- 1 (out of X which equals 3) Print "*" Y <- 2 (out of X which equals 3) Print "*" Y <- 3 (out of X which equals 3) Line 3, 3 "*" printed So for every line 'X' in my case 5 (Lines), Im going to use 'Y' to print the number of stars on that line - which equals X stars - 1st line has 1 star, 2nd has 2 stars, 3rd line has 3 stars, 4th line has 4 stars, 5th line has 5 stars btw, in between the two loops X Y ie NEXT Y NEXT X

我会做类似的事情

I would have done something like

NEXT Y PRINT (something to make a new line) NEXT X

但是自从我做了任何BASIC以来已经很长时间了,所以你必须要看一下 有帮助吗? 如果你缩进,它也更容易看到'循环' em $ / $

but its been a long time since Ive done any BASIC so you'll have to look that up does that help ? Its also easier to see 'loops' if you indent them

FOR X = 1 to LINES FOR Y = 1 to X NEXT Y NEXT X

[/ EDIT]

[/EDIT]

我建​​议使用调试器,但我不记得它是否在QBasic中有效。 从Standord University试试这个链接: 学习编程 [ ^ ] 和这一个 www.khanacademy/computing/computer-programming/programming/l ooping / p / nested-for-loops [ ^ ] 根据需要搜索教程。 I would recommend to use the debugger, but I don't remember if it was efficient in QBasic. Try this link from Standord University: Learn to Program[^] and this one www.khanacademy/computing/computer-programming/programming/looping/p/nested-for-loops[^] Search for tutorials as you need.

更多推荐

学习qbasic并试图理解我刚写的代码

本文发布于:2023-11-08 16:02:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569834.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我刚   代码   qbasic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!