Computer Science, asked by Nainagupta18, 19 days ago

WAP to display your name 20 names on different time, using for statement​

Answers

Answered by akshith2409
1

Hello friend, I wrote your answer in python.

name = input("What's your name? ")

print(*(name for i in range(10)), sep='\n')

Hope this Helps buddy :)

Answered by Anonymous
2

Java Programming

We'll be using \tt{for} loop to print the name on the screen for 20 times.

\tt{for} loop in java is used to execute a specific set of statements a fixed number of times.

The syntax for the \tt{for} lop is:

for (initialization; testCondition; update)

{

   // statements inside the body of the loop

}

\rule{300}{2}

The Program

public class Main    // Creating class

{

  // The MAIN function

public static void main(String[] args) {

   // Using for loop to print a name 20 times

   for (int i = 1; i <= 20; i++)

   {

       // Printing the name on the screen

       System.out.println("lHello World");

   }

 }

}

\rule{300}{2}

Program Explanation

In the above program, \tt{int \; i = 1;} is the initialization statement which is executed only once.

\tt{i &lt;= 20} is the test condition of the loop. The loop ends when it's false.

\texttt{++i;} is the update statement. It is equivalent to \tt{i=i+1;}.

Attachments:
Similar questions