answersLogoWhite

0

How to use while loop statement in php?

Updated: 9/14/2023
User Avatar

Wiki User

15y ago

Best Answer

simple code example: <? while ($a < 10 ) { echo "$a, "; $a++; } echo "Finished"; ?> Will output, 1, 2, 3, 4, 5, 6, 7, 8, 9, Finished this will run through the loop WHILE $a is less than 10, outputting the value of $a to the screen. once $a = 10 then the loop will end and continue on with the rest of the script

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to use while loop statement in php?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Basic Math

What are the similarities between php statement and javascript statement?

PHP and JavaScript are quite different, given that PHP is server-side and JS is (typically) client-side. However, with Node.JS -for example- you can now also use JS on the server-side. They are both interpreted languages (scripts), they are both incredibly popular languages running a huge amount of the internet, and they are both some of the simplest languages to start out in.


What are the purpose of test condition in a loop statement in qbasic?

The purpose of using a 'test condition' inside of a loop statement/which is also called a 'conditional loop'; is to make the loop STOP counting. Otherwise, you would have gone and created what is known as being called an 'endless loop'; which just keeps on running really quite endlessly, forevermore...! To give a quick example, let's compare... CONDITIONAL LOOP EXAMPLE num% = 0 DO num% = num% + 1 PRINT num%; LOOP UNTIL num% = 3 END Output... 1 2 3 Press any key to continue... Here, when the LOOP's test condition is met: (num%=3); then, the loop stops counting up any further; the DO/LOOP block structure is broken out of; and, the final END statement will get executed. UNCONDITIONAL LOOP EXAMPLE Next, let's try re-writing the same above program; by removing the conditional statement part of the LOOP which says: (UNTIL num%=3)... num% = 0 DO num% = num% + 1 PRINT num% LOOP END Output... 1 2 3 4 5 6 7 8 9 10 11 12 .... ...because there is no conditional test statement to make the loop stop repeating itself; therefore, it just keeps on endlessly counting upwards, instead; the program never breaks out of the DO/LOOP block; and, therefore never gets to reach the final END statement. To make an 'unconditional loop' stop repeating itself inside of QBASIC IDE/Integrated Development Environment; then, use combination key press: [CTRL] + [BREAK]; and, this should make an 'endless loop' stop repeating itself any further; and, return you straight back to the Editor Screen where you can futher change/edit your code.


Why we use javascript as we have a powerful scripting language php?

First of all, PHP is server side, Javascript is client side. You cannot detect mouse gestures or any clicks with PHP the same way you cannot read a file or modify it or process a form (unless you use AJAX of course). Also, although I love PHP, and it has useful extensions such as the GD library, PHP is not a very good language. Overall we use javascript and PHP because they are used for two completely different things.


What is syntax in php?

We can use php tags in different ways. &lt;?php //php code to be written here ?&gt; OR &lt;? //php code ?&gt; This tag will not work when we using editors such as macromedia dreamweaver. OR &lt; script language="php"&gt; //php code &lt;/script&gt;


What is the difference between simple php and core php?

The terms &quot;simple PHP&quot; and &quot;core PHP&quot; are not commonly used in the web development community, but based on the context, we can provide an explanation of what they might refer to: Simple PHP: &quot;Simple PHP&quot; is a vague term that could refer to using basic PHP syntax and features without incorporating any advanced frameworks or libraries. In this context, &quot;simple PHP&quot; typically means writing PHP code without relying on additional tools or external dependencies. It implies a straightforward and minimalistic approach to PHP development. Core PHP: &quot;Core PHP&quot; refers to the fundamental and essential features of the PHP programming language itself. Core PHP includes the core functions, language constructs, and syntax provided by PHP without the use of any external libraries or frameworks. It involves writing PHP code in its purest form, utilizing the features and functionalities offered by the PHP language without any additional abstractions. In summary, &quot;simple PHP&quot; suggests a minimalistic approach to PHP development, while &quot;core PHP&quot; focuses on utilizing the essential features and syntax of the PHP language itself without relying on external dependencies. It's worth noting that both terms are not widely used, and their exact definitions may vary depending on the context and the individuals using them.

Related questions

Why you use while function in c?

It is a statement; you can create a loop with it: while (&lt;condition&gt;) &lt;statement&gt;


Can a continue statement be used in a switch statement?

If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).


Why you use for loop inside switch statement?

Because you have to repeat something. (Or you can use while-loop, too.)


What is the difference between while dowhile?

While: If we can use while statement it will check the condition then proceed further loop statement.DoWhile: If we use dowhile, first execute loop statement then check the condition.


Is it possible to use a for loop in place of a while loop?

Yes. while loop consist of only condition statement to make for loop look as while loop we can use syntax shown below: for(;condition;) eg: for(;i&lt;=n;)


What is while statement and how is it used?

You use a while statement to introduce a conditional loop. Unlike a for loop which is typically used for counted loops, a while loop is used whenever a statement must iterate while an expression evaluates true. The expression is evaluated at the start of each iteration.


Is possible to use a for loop in place of a while loop?

Yes, it's easy:Old: while (expression)statementNew: for (; expression;)statement


Difference between break and continue statements in wml?

Break statements:-its terminates the current while or for loop and continue the program execution from the statement following the terminated.NOTE:-note that it is wmlscript syntax error to use the break statement outside of while or a for statements.example;Breakstatement:Break;Continue statement:-this statement terminate execution of a block of statementin while or for loop and continues execution of loop with the next iteration.note that the continue statement does not terminate the execution of loop and also is wmlscript syntax error to use the break statement outside of while or a for statements.-> in while loop, it jumps back to the condition.-> in for loop,it jumpsto the update expression.syntax:continuestatement:continue;


Why you use if loop in telecoms?

No such thing as if-loop. if-else statement is not a loop.


Can you Compare while and do-while?

The 'while' statement evaluates its expression at the beginning of the loop, while a 'do while' statement evaluates its expression at the end of the loop. The 'while' statement might execute no times. The 'do while' statement will execute at least one time. It depends on what you want to do, and on how you want to use the side effects, if any, of the expressions in the expression. (Before or after)


Can break statement be used without any loop?

The Break statement should generally get executed in some loop or switch statement. The below code will give compiler error. void main() { printf("12"); break; printf("14"); }


What is the difference between looping statements - c program?

Repetition. For example the following lines do the same thing: while (expression) statement; LABEL: if (expression) {statement; goto LABEL; } Or these: for (exp1; exp2; exp3) statement; exp1; LABEL: if (exp2) {statement; exp3; goto LABEL; }