带有For ... Next语句的星型 [英] Star Patterns with For...Next Statements

查看:103
本文介绍了带有For ... Next语句的星型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想要代码的答案-我想知道我的Pattern 2为什么起作用?我想知道背后的原因!请帮忙!

我在整个Google上进行了搜索,提到了我的课本和课堂笔记,但我被卡住了!我觉得自己缺少了一些小东西,但那小东西却把我搞砸了.我需要使用For ... Next语句对以下模式进行编码.这是我到目前为止的代码,部分原因是我找出了5种模式之一,但是我不知道它为什么起作用!好沮丧!请帮忙!

I don''t want the answer to the code - I want to know why did my Pattern 2 work? I would like to know the why behind it! Please Help!

I have searched all over google, referred to my text book and my class notes and I am stuck! I feel like I am missing something small but that small thing is messing me up. I need to code the below patterns using For...Next statements. Here is the code I have so far, part of this is that I figured out one of the 5 patterns but I don''t know why it worked! So frustrated! Please help!

Module Module1

    Sub Main()
        Console.WriteLine("Pattern 1")

        Dim count As Integer
        Dim count2 As Integer

        For count = 0 To 10
            For count2 = 1 To 10
                Console.WriteLine("*")
            Next
        Next

        Console.WriteLine()

        Console.WriteLine("Pattern 2")

        For count = 0 To 10
            For count2 = 1 To 10 - count
                Console.Write("*")
            Next
            Console.WriteLine()

        Next

        Console.ReadLine()

    End Sub

End Module



模式1
*
**
***
****
*****
******
*******
********
*********
**********

模式2
**********
*********
********
*******
******
*****
****
***
**
*

模式3
**********
*********
********
*******
******
*****
****
***
**
*

模式4
*
**
***
****
*****
******
*******
********
*********
**********

模式5
*
***
*****
*******
*********
*******
*****
***
*



Pattern 1
*
**
***
****
*****
******
*******
********
*********
**********

Pattern 2
**********
*********
********
*******
******
*****
****
***
**
*

Pattern 3
**********
*********
********
*******
******
*****
****
***
**
*

Pattern 4
*
**
***
****
*****
******
*******
********
*********
**********

Pattern 5
*
***
*****
*******
*********
*******
*****
***
*

推荐答案

因为这看起来像是一项家庭作业,没有代码,只是一般说明.只有自己做运动才能对您有用.

您使用立即常数 10次四次.这是不支持的.如果无法或无法从某些数据(用户输入,配置文件,资源等)中获取值,则应将其声明为常量
As this looks like a home assignment, no code, just general directions. An exercise can only be useful for you if you do it by yourself.

You use the immediate constant 10 four times. This is unsupportable. If you cannot or don''t get a value from some data (user input, configuration file, resource, etc.), you should declare it as a constant
const uint maximumLineLength = 10;


您只有3种差异模式,而不是5种:#1,#2和#5.显然,然后#5中的两个仅需要两个嵌套循环,并且可以在不同方向上重复两次外部循环,但是我建议您考虑使用从1到20的外部循环的解决方案( 2 * maximumLineLength),但只有一个.

如果您不明白为什么某些项目无法按计划进行,请使用调试器.您应该自己开发修复代码的基本技能.

—SA


You have only 3 difference patterns, not 5: #1, #2 and #5. It is apparent that two of then needs only two, nested, loops, and outer loop in #5 could be repeated twice in different direction, but I would advise you to think about the solution where you use the outer loop from 1 to 20 (2 * maximumLineLength), but only one.

If you don''t understand why something doesn''t work as planned, use the debugger. You should develop the basic skills of fixing code by yourself.

—SA


这篇关于带有For ... Next语句的星型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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