C# for loop

Joined
Sep 4, 2022
Messages
129
Reaction score
16
hello !

learning is hard time, but while you understand the requirement everythings fine !

you have the wildcard, and 'at each level' they're adding one wildcard.
It's the only 'char' | 'symbol' existing in this exercice.

'at each level' implies a repetition for the simple work to be done : so a 'loop' is needed.
'at each level' , one more 'wildcard' is added to the String pattern.


C#:
int max = 18 ; // random max limit
string wcard_pattern = "*" ; // first pattern to display, using string is easy.

// by a for loop
for( i = 0 ; i < max ; i++ ){
// display about the first pattern, and at each loop lap :
    console.writeline(wcard_pattern) ;
// end_display to console


// then we work on wcard_pattern content ( and values )
    wcard_pattern += "*" ;
// equal to:  wcard_pattern = wcard_pattern + "*" ;
// it's syntax shortcut


}

// reset of max , and reset of wcard_pattern

max = 25 ; // random value
wcard_pattern = "*" ; // 1 wildcard as start content



// by a while loop :
while( i < max && i++ ){ // 2 tests conditions are used.
// one check the total of wcard_pattern until i = max ( not always returning '1', when '0' it exit the loop )
// one operate an incrementation of i. ( function always returning '1' )
// as one of the two tests fails, it will exit the loop.

    console.writeline(wcard_pattern) ;

    wcard_pattern += "*" ;

}
 
Joined
Jul 4, 2023
Messages
370
Reaction score
41
just a different approach ...

[ on-line ]
C#:
int max = 20;
string stars = new String('*', max);
for (int i=0; i<max; i++)
   Console.WriteLine(stars.Substring(0, i));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,286
Latest member
ChristieSo

Latest Threads

Top