![]() ![]() In this example, there is a combination of two stars patterns upper triangle and lower triangle. Inside the inner loop, check if the index of the inner loop does not last then print star () at first and last index of the inner loop. Inside this loop, create an inner loop to print columns. Both the loops defined are dependent on the value of i. Steps to create a hollow triangle star pattern: Create an outer loop to print rows. In this example, three loops are used, one for the number of rows, second for the printing of spaces and third to print the stars. Also in this example, we are using j for loop to print spaces and a new k for loop is used to print stars *. In this example, the value I for loop is iterated 5 times, as the number of rows in the star pattern is 5. This will stop once the condition of i is greater than 5 and will print the desired output. Next for the value of 2, the j loop will print 4 stars, for the next value 3, the j loop will print 3 times and so on. For the first time as we want 5 stars in the first row, so for the first value of i as 1, the j loop will print 5 stars. The j for loop is used to print * depending upon the value of i. In this example, the i for loop will loop 5 times as we want 5 rows. Inside the for loop is, again a for loop for columns, where the variable j is initialized to 0 and this loop will print stars(*) in the first row, and will loop till the condition $j' As per the syntax of for loop, the outer loop begins with 0, checks the condition whether it is less than 5 if yes, it will go inside the loop.The inner for loop represents columns of the pattern. Next, the inner for loop also iterate 5 times starting from 0 and ends with a value less than the value of 5.The outer for loop represents rows of the pattern. The outer for loop with a value of I iterate 5 times starting from 0 and ending with value 5 as we want five rows. The outer loop is for rows and the inner loop is for columns. We will be using two loops, outer and inner loop. #For loop in php software#Web development, programming languages, Software testing & others #For loop in php free#Start Your Free Software Development Course ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |