如何执行此特定的For ... next循环? [英] How to do this specific For...next loop?

查看:82
本文介绍了如何执行此特定的For ... next循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经获得了将2用于...下一个循环以创建字符串立方体的任务.

I've gotten the assignment to use 2 for...next loops to create a cube of a string.

例如,如果输入T和3,则输出应为:

For example, if you input T and 3 the output should be:

T T T

T T T

T T T

您如何在控制台中执行此操作?因为for ... next循环完全拒绝接受字符串.

How do you do this in console? Because for...next loops downright refuse to accept strings.

推荐答案

您应该尝试使用For/Next,并使用输入数字在继续使用第二个For/Next前,输入输入字符的次数.那么第一个For/Next将位于自第一个For/Next之后的第二个For/Next之内 会写三个字母,并且For/Next会在里面(第二个For/Next)会写我想写的行,以便在控制台显示区域中向下移动.

You should try using a For/Next using the input number to write the input character the amount of times the number requires before moving on to using the second For/Next. Then the first For/Next will be within the second For/Next since the first For/Next will write the letter three times and the For/Next it will be inside of (the second For/Next) will write line I suppose in order to move downwards in the console display area.

对于i = 1 To(用于获取输入数字的某个整数)

For i = 1 To (some integer you use to get the input number)

   Console.Write(一些包含字符的字符串变量)

   Console.Write(some string variable that contains the character)

下一个

对于上述代码,您应该声明一个整数变量,当用户输入数字时,将读取的行转换为整数.

With regard to the above code you should declare an integer variable and when the user goes to enter the number convert the read line to integer.

将InputNr设置为整数= 0

Dim InputNr As Integer = 0

InputNr = CInt(Console.ReadLine)

InputNr = CInt(Console.ReadLine)

对于i = 1的输入Nr

For i = 1 To InputNr

   Console.Write(InputChar)

   Console.Write(InputChar)

下一个

当然,您应该使用Console.WriteLine来建议用户输入一个字符或数字,然后再阅读该用户输入的字符或数字.但是,如果用户输入非数字值并且控制台应用程序尝试运行该应用程序,则该应用程序可能会崩溃 将其转换为整数值.

Of course you should use Console.WriteLine to advise the user to enter either a character or number and follow that with reading the character or number the user enters. But the app may crash if the user enters a non-numeric value and the console app tries to convert it to an Integer value.

我还使用了以下应用程序中的Console.Clear在用户输入每个值后清除屏幕.并且在显示使用For/Next语句输入的值之后.

I also used Console.Clear in the below app to clear the screen after the user entered each value. And also after displaying the value entered using the For/Next statements.


这篇关于如何执行此特定的For ... next循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆