惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
GbyAI
GbyAI
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
B
Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
雷峰网
雷峰网
爱范儿
爱范儿
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
Jina AI
Jina AI
P
Proofpoint News Feed
A
About on SuperTechFans
I
InfoQ
F
Fortinet All Blogs
L
LangChain Blog
T
Tailwind CSS Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
DS - while loop
AravindhBalakrishnan · 2026-05-26 · via DEV Community

AravindhBalakrishnan

Let's discuss about while loop.

We need to print a particular value say 5 for 10 times.

print(5)
print(5)
print(5)
print(5)
print(5)
print(5)
print(5)
print(5)
print(5)
print(5)

Output : 

5
5
5
5
5
5
5
5
5
5

writing the above code give the expected output as expected, but if we need to print the same for 10000 times or 1000000 times we can write that many lines which will take more time to write and it is difficult to know whether we have written the exact number of times to print the same line.

In order to over this difficulty and to perform the same repeated task over and over again we can use ** while ** loop. It provides us to write repeated task in few lines of code.

count = 1
while count<=10000:
      print(5)
      count = count+1

This will print 5 for 10000

Extra Insight -
This print statement will print every 5 in new line , if we want to print it in same line we need to change the default value of the end is\n in print statement to end = " " this is will give space after every print function

count = 1
while count<=100:
      print(5 , end = " ")
      count = count+1

In the above 5 will be printed in the same line with space between them.

Lets us see a different program to print 1 2 3 4 5 6 7 8 9 10 instead
of 5 5 5 5 5 5 5 5 5

count = 1;
while count <= 10:
      print(count , end = " ")
      count = count + 1 

Output : 1 2 3 4 5 6 7 8 9 10 

To perform loop we need 3 important sections in a program :

  • Initialisation
  • Condition
  • Increment / Decrement condition.

Lets discuss other examples for while loop

count = 1
while count < = 5:
     print (count+5 , end = "  ")
     count = count + 1

Output :  6 7 8 9 10 

Lets us do another task to print table of 3 . h

1 * 3 = 3
2 * 3 = 6
.
.
.
.
10 * 3 = 30

Here we perform repeated task to print * 3 = in all the output line but value of 1 and 3 in first line is change to 2 and 6 in the second line which continues to go on till 10 and 30 in line 10. so we can use while loop to perform the same action and do it.

count = 1
while count <= 10:
     print(count, " * 3 = " , count * 3)
     count = count +1 

Output : 
1  * 3 =  3
2  * 3 =  6
3  * 3 =  9
4  * 3 =  12
5  * 3 =  15
6  * 3 =  18
7  * 3 =  21
8  * 3 =  24
9  * 3 =  27
10  * 3 =  30

While going through the above context and examples we can clearly understand the concept of loop and how loop is written to reduce the work of the programmer and to do repeated task until the condition fails.