Do You Know How to use For Loops in PHP - Coding Cyber

Do You Know How to use For Loops in PHP

Do You Know How to use For Loops in PHP

Quickly Navigate to Other Sections in PHP Tutorials

Useful PHP Functions

for() Loop in PHP, for loop executes the code inside the block for a specified number of times.

Syntax of for() Loop in PHP

for (init counter; test counter; increment counter) {
code to be executed;
}

Example code of for() Loop in PHP
Here in this example, we are initiating variable i as 1, condition to check is if variable i is less than or equal to 10. And increment i till the condition fails.

If i = 1, i is less than 10, Value to be displayed is 1. then var i value increments by one.
If i = 2, i is less than 10, Value to be displayed is 2. then var i value increments by one.
If i = 3, i is less than 10, Value to be displayed is 3. then var i value increments by one.
If i = 4, i is less than 10, Value to be displayed is 4. then var i value increments by one.
If i = 5, i is less than 10, Value to be displayed is 5. then var i value increments by one.
If i = 6, i is less than 10, Value to be displayed is 6. then var i value increments by one.
If i = 7, i is less than 10, Value to be displayed is 7. then var i value increments by one.
If i = 8, i is less than 10, Value to be displayed is 8. then var i value increments by one.
If i = 9, i is less than 10, Value to be displayed is 9. then var i value increments by one.
If i = 10, i is equal to 10, Value to be displayed is 10. then var i value increments by one.
If i = 11, i is not equal to 10 and not less than 10, here for loop breaks out. And continue to execute next block of code after for loop.

for (\$i = 1; \$i <= 10; \$i++) { echo \$i; }

Related Posts
No related posts for this content
Vivek Vengala

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8428426,"math_prob":0.99511904,"size":1826,"snap":"2019-26-2019-30","text_gpt3_token_len":521,"char_repetition_ratio":0.1805708,"word_repetition_ratio":0.3307888,"special_character_ratio":0.29572836,"punctuation_ratio":0.12844037,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9913519,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-06-26T04:04:45Z\",\"WARC-Record-ID\":\"<urn:uuid:1040b4e2-2a6e-46f2-9ee9-03ee3d495fbb>\",\"Content-Length\":\"115003\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c4259550-9c6c-49b3-857c-43b70749e5a2>\",\"WARC-Concurrent-To\":\"<urn:uuid:fcd95feb-2f50-4602-b527-a4dc7fa4f862>\",\"WARC-IP-Address\":\"68.66.224.17\",\"WARC-Target-URI\":\"https://codingcyber.org/for-loops-in-php-7914/?shared=email&msg=fail\",\"WARC-Payload-Digest\":\"sha1:ALPULPKQ2FQ7MDIEUICBP7FQYSAK5U6I\",\"WARC-Block-Digest\":\"sha1:Y5G76M4FBRACKGFXFK42BVJZD5CP76HI\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-26/CC-MAIN-2019-26_segments_1560628000164.31_warc_CC-MAIN-20190626033520-20190626055520-00054.warc.gz\"}"}