Tagged articles
for loop
77 articles · Page 1 of 1
This article analyzes whether try-catch blocks should be placed inside or outside for loops in Java, demonstrating how placement affects loop continuation after exceptions, examining JVM exception table mechanics, and comparing memory performance implications.
Exception HandlingJVMJava
0 likes · 6 min read

This article explains the critical behavioral difference when placing try-catch inside versus outside a for loop: outside placement terminates the loop on exception, while inside allows continuation. It also analyzes performance implications, showing negligible overhead when no exceptions occur but increased memory consumption if many iterations throw exceptions, and details the JVM exception table mechanics that underlie this behavior.
Exception HandlingJavabytecode
0 likes · 6 min read

A production outage caused by a Java Stream pipeline processing one million orders revealed massive memory overhead and CPU‑bound garbage collection, prompting a benchmark that showed a handcrafted for‑loop to be up to twenty times faster and far more memory‑efficient.
JavaMemoryStream API
0 likes · 10 min read

The article examines the hidden pitfalls of C‑style for loops, explains how languages like Python, Rust, Swift and Go replace them with safer, more readable constructs, and discusses when the traditional C for loop remains advantageous for low‑level or performance‑critical code.
C languageCode safetyGo
0 likes · 7 min read

This tutorial‑style note walks through Python’s pass statement, the mechanics of while and for loops (including nested loops and common pitfalls), the use of break and continue, and a comprehensive overview of string creation, slicing, case conversion, searching, replacement, and encoding, all illustrated with concrete code examples and expected outputs.
PythonSlicingString Manipulation
0 likes · 23 min read

This article explains step‑by‑step how to use both while‑loops and for‑loops in Python to generate a formatted 9×9 multiplication table, detailing the loop logic, code syntax, and the exact output produced for each row.
LoopsPythonfor loop
0 likes · 10 min read

This tutorial explains how break and continue control loop execution in Python, provides concrete while‑loop examples with their outputs, and demonstrates both for‑ and while‑based nested loops for printing multi‑row patterns, illustrating syntax and behavior step by step.
ContinuePythonbreak
0 likes · 4 min read

This article examines why traditional JavaScript for loops are often suboptimal and introduces more readable, functional, and powerful alternatives such as array methods, for...of, for...in, and the spread operator, while also outlining scenarios where the classic for loop still shines.
Array MethodsES6JavaScript
0 likes · 7 min read

This article explains how placing a try‑catch block inside or outside a Java for loop affects exception handling, loop termination, and performance, providing code examples, execution results, memory analysis, and practical guidance for choosing the appropriate approach based on business needs.
Exception Handlingfor loopperformance
0 likes · 5 min read

While the classic JavaScript for loop remains fundamental, modern ECMAScript features and array methods like forEach, map, filter, and newer constructs such as for…of and the spread operator offer more readable, functional, and often more efficient alternatives, each suited to different scenarios.
Array MethodsES6JavaScript
0 likes · 7 min read

While both while(1) and for(;;) create infinite loops in C, this article explains their syntax, execution flow, and demonstrates through compiled assembly that, despite subtle differences, they generate identical machine code, helping developers understand any performance or size implications.
C++assemblycode optimization
0 likes · 5 min read

This guide explains how to define, pass, iterate over, and return arrays within PHP functions, covering array creation with array(), parameter passing, traversal using both for and foreach loops, and returning modified arrays, complete with full code examples for each step.
Code TutorialPHParrays
0 likes · 5 min read

This article examines why the traditional JavaScript for loop is often suboptimal and explores newer, more readable and functional iteration methods such as array helpers, for...of, for...in, and the spread operator, while also outlining scenarios where the classic for loop still shines.
Array MethodsES6JavaScript
0 likes · 7 min read

This article examines whether to put a try‑catch block inside or outside a Java for loop, discussing scenarios, performance implications, and providing code examples to help developers choose the most appropriate approach.
Best PracticesException Handlingfor loop
0 likes · 5 min read

This article explains why caching an array's length in a JavaScript for‑loop is often unnecessary for standard arrays, but can cause serious performance issues with live DOM collections, and shows the proper way to handle both cases efficiently.
DOMJavaScriptarray length
0 likes · 5 min read

Python’s else clause, often misunderstood as part of if‑else, actually executes only when a for or while loop completes without encountering a break, offering a concise way to handle search patterns, break detection, and post‑loop actions, but it can confuse developers unfamiliar with this subtle feature.
Code Patternscontrol flowfor loop
0 likes · 7 min read

Learn the three core C++ loop structures—for, while, and do-while—including their syntax, practical examples, control statements like break and continue, plus common pitfalls to avoid for reliable programming.
C++Loopscontrol statements
0 likes · 6 min read

This article introduces Python control flow, explaining conditional statements (if, elif, else) and loop constructs (for, while) with clear syntax, practical examples, tips, and exercises to help readers master decision‑making and iteration in their programs.
Code Examplescontrol flowfor loop
0 likes · 7 min read

This article explains Go's flow‑control constructs—including conditional statements, loops, switch branches, and special statements like break, continue, and goto—provides syntax details, highlights key characteristics, and offers multiple code examples to help developers write clear and efficient Go code.
Flow ControlGofor loop
0 likes · 9 min read

This article explains how positioning a try‑catch block either outside or inside a Java for‑loop influences exception handling, loop termination, performance, and memory consumption, providing code examples, execution results, and practical recommendations for backend developers.
Javaexception-handlingfor loop
0 likes · 6 min read

This article demystifies Python’s for-loop by explaining how iterable objects and iterators work under the hood, illustrating the iterator protocol with code examples, and providing practical custom iterator implementations, common pitfalls, and tips for efficient data processing.
IterablePythondata processing
0 likes · 9 min read

This article explains Python’s for loop syntax, walks through eleven practical examples—from simple list traversal to nested loops and dictionary manipulation—and highlights key usage tips, performance considerations, and common pitfalls to help developers write clear, efficient iterative code.
PythonTutorialexamples
0 likes · 8 min read

Through benchmark tests, memory analysis, and code examples, this article presents ten compelling reasons why using a traditional for loop to traverse Java Lists often outperforms Stream.forEach in terms of performance, memory usage, control flow, exception handling, mutability, debugging, readability, and state management.
DebuggingJavaMemory
0 likes · 16 min read

Although the classic JavaScript for loop remains fundamental, modern ECMAScript features and array methods like forEach, map, filter, and newer constructs such as for…of provide more readable, functional, and concise ways to iterate, while the traditional loop still has niche uses where precise control or performance matters.
ES6JavaScriptfor loop
0 likes · 7 min read

This article explains the functional differences, performance impact, and practical considerations of placing a try‑catch block either outside or inside a Java for loop, illustrating each approach with code examples, execution results, and recommendations based on business requirements.
Exception HandlingJavabackend development
0 likes · 6 min read

This article benchmarks various JavaScript looping constructs—including for, while, do‑while, for‑of, forEach, map, filter, reduce, some, every, and find—by moving 50 million items between arrays and measuring execution time to determine the fastest approaches.
benchmarkfor looploop performance
0 likes · 8 min read

The article explains the trade‑offs of placing a Java try‑catch block inside versus outside a for‑loop, illustrating both approaches with code examples, and advises choosing the placement based on whether you need unified error handling or per‑iteration resilience, while also noting a free book promotion.
Exception HandlingJavabackend development
0 likes · 4 min read

This article explains the differences between placing a try‑catch block inside or outside a for loop in Java, covering usage scenarios, execution results, performance impact, and practical advice for choosing the appropriate approach during development and interviews.
Best PracticesException HandlingJava
0 likes · 6 min read

This article explains the different effects of placing a try‑catch block inside versus outside a for loop in Java, covering usage scenarios, performance impact, memory consumption, and practical recommendations for choosing the appropriate approach during development.
Exception HandlingJavabackend development
0 likes · 6 min read

This guide walks beginners through Python's control flow structures—if statements, for loops, and while loops—explaining their syntax, demonstrating multiple conditional checks, iteration over sequences, and combined usage with clear code examples that illustrate filtering, accumulation, and prime number detection.
control flowfor loopif statement
0 likes · 4 min read

This article showcases practical JavaScript snippets—including a 40‑iteration for‑loop, various if‑statement patterns, hidden password field tricks, complex else chains, while‑loop limits, and odd/even detection—illustrated with screenshots and commentary to help developers understand control flow and coding style nuances.
Code ExamplesJavaScriptcontrol flow
0 likes · 4 min read

This article explains why loops are needed in programming, introduces Python's for‑in and while loops with practical examples such as summing numbers, generating multiplication tables, guessing games, and solving prime and GCD/LCM problems, and discusses break, continue, and nested loops.
Loopsfor loopfundamentals
0 likes · 9 min read


21CTOApr 9, 2024 · Fundamentals
Go 1.22 changes the for‑loop variable scope so that each iteration receives its own copy, eliminating the long‑standing closure pitfall that caused incorrect outputs in concurrent programs and simplifying range usage for developers.
GoGo 1.22closure
0 likes · 6 min read

This article demonstrates four methods to reverse a PHP array—including the built‑in array_reverse() function, a manual for‑loop swap, an array_reduce() technique, and a combination of array_multisort() with array_column()—explaining their usage, code examples, and output results.
BackendPHParray_column
0 likes · 6 min read

This article compares placing a try‑catch block inside versus outside a Java for‑loop, showing concrete code examples, execution results, memory‑usage measurements, and practical recommendations based on how exceptions affect loop termination and performance.
Best PracticesException HandlingJava
0 likes · 7 min read

This article presents more than ten practical techniques for writing faster, cleaner Java for‑loops, covering basic size caching, reverse iteration, iterator usage, enhanced for‑loops, nested loop reduction, exception handling placement, and method‑call minimization to improve overall program performance.
Coding Best PracticesJavafor loop
0 likes · 8 min read

This article compares Java 8 Streams with traditional for‑loops through concrete code examples, benchmark results, parallel‑stream speedups, and discusses scenarios where Streams excel or fall short, helping developers decide when to prefer Streams over loops.
Code ReadabilityJavaParallelStream
0 likes · 10 min read

This article outlines over ten practical techniques for optimizing Java for‑loops, including caching list size, using reverse iteration, employing iterators, leveraging enhanced for‑each loops, minimizing method calls, and handling exceptions efficiently, helping developers write cleaner and more performant code.
best-practicescodingfor loop
0 likes · 7 min read

This article explains how positioning a try‑catch block inside or outside a Java for‑loop affects exception handling, loop termination, performance, memory usage, and provides practical guidance for choosing the appropriate placement based on business requirements.
BackendException HandlingJava
0 likes · 7 min read

This tutorial explains how to use a PHP for loop to iteratively add the numbers from 1 to 100, shows the complete code example, and clarifies the loop syntax and the meaning of the $sum += $x expression for beginners.
BackendPHPSum
0 likes · 3 min read

This article explains why deleting elements from a Java List while iterating with a for loop is unsafe, demonstrates the correct approach using an Iterator or removeIf, and analyzes common pitfalls of both classic for and enhanced foreach loops.
ConcurrentModificationExceptionListfor loop
0 likes · 7 min read

This article explains the syntax and execution semantics of while(1) and for(;;) in C, compares their generated assembly code, and demonstrates through a practical gcc compilation that both constructs produce identical machine code for an infinite loop.
C++Compilerassembly
0 likes · 7 min read

While(1) and for(;;) both create infinite loops in C, but this article explains their syntactic forms, execution semantics, and demonstrates through compiled assembly that they generate identical machine code, highlighting subtle differences and confirming they are functionally equivalent.
C++assemblyfor loop
0 likes · 5 min read

This article explains why Python developers should avoid explicit for loops, demonstrating how list comprehensions, generator expressions, map/reduce, itertools, and function extraction can produce more concise, readable, and maintainable code while reducing indentation and improving structure.
Code ReadabilityPythonfor loop
0 likes · 6 min read

This article explains the fundamental differences between JavaScript's for loop and forEach method, covering their syntax, behavior, performance characteristics, iterator concepts, usage scenarios, and practical code examples for array traversal and manipulation.
JavaScriptarrayfor loop
0 likes · 12 min read

The article explains the origin of Java’s for(;;) infinite loop syntax, compares it with while(true) through source‑code searches and bytecode analysis, and concludes that both constructs compile to identical bytecode, making performance differences negligible while also providing related promotional links.
JDKJavafor loop
0 likes · 5 min read

This article explores whether elements can be deleted or modified within Java's foreach loop, compares it with traditional for loops, explains the iterator behavior that triggers ConcurrentModificationException, and demonstrates the correct use of iterator.remove() and object property updates.
ConcurrentModificationExceptionJavaList
0 likes · 8 min read

This guide explains the syntax, creation, and execution of Bash for loops, covering basic structures, numeric and string iteration, step values, conditional breaks, and essential commands like chmod and ./script.sh to automate repetitive tasks efficiently.
automationfor loop
0 likes · 7 min read

This article demonstrates that in Python, plain while and for loops are significantly slower than using built‑in functions like sum or applying a direct mathematical formula, because the former execute extra Python‑level boundary checks and increments, making the latter the most efficient looping alternatives.
Sumbuilt-in functionsfor loop
0 likes · 7 min read

An interview question about choosing i++ or ++i in a for‑loop leads to a bytecode‑level analysis that reveals both forms compile to the same ++i instruction after JVM optimization, making their performance essentially identical in typical Java loops.
Javabytecodefor loop
0 likes · 8 min read

This article explains common pitfalls when deleting elements from a Java List—such as index shifting, ConcurrentModificationException in foreach loops, and the difference between removing by index versus by object—and provides reliable solutions using index adjustment, reverse iteration, and Iterator.remove().
ConcurrentModificationExceptionJavaList
0 likes · 8 min read

The article explains that Java’s for(;;) infinite loop and while(true) are historically inherited from C, produce identical bytecode under javac, and their performance depends on the JVM implementation rather than the source syntax.
JVMJavafor loop
0 likes · 5 min read


21CTOSep 2, 2021 · Fundamentals
Learn how to dramatically improve Java for‑loop performance by applying seven practical techniques—including caching list size, using combined loop variables, iterating backwards, leveraging Iterator, enhanced for‑each syntax, minimizing nested loops, and moving exception handling outside—each with clear pros, cons, and code examples.
codingfor loopoptimization
0 likes · 5 min read

This article compares five JavaScript iteration constructs—classic for, forEach, map, for...in and for...of—explaining their origins, semantics, performance characteristics, and appropriate use‑cases, while providing concrete code examples and guidance on breaking, continuing, and avoiding common pitfalls.
JavaScriptfor loopfor...of
0 likes · 12 min read

The article explains the historical origin of Java's for(;;) loop, compares it with while(true) in terms of readability and bytecode generation, and shows that both constructs compile to identical bytecode in the standard javac compiler, making performance differences negligible.
JavaLoopsbytecode
0 likes · 4 min read

This article explains the origin of Java’s for(;;) infinite loop syntax, compares it with while(true), shows how both compile to identical bytecode in JDK 8, and concludes that performance differences depend on the JVM implementation rather than the source construct.
JDKJavafor loop
0 likes · 4 min read

This article explains Python's for loop in depth, covering basic syntax, the optional else clause, the concepts of iterables and iterators, how to implement custom iterators and iterable objects, the loop's execution flow, an equivalent while‑loop implementation, and a step‑by‑step disassembly of the generated bytecode.
Iterablebytecodedisassembly
0 likes · 12 min read

This article explains the purpose, syntax, and practical usage of Python's for loop, covering iteration over lists, strings, ranges, conditional filtering, loop control statements, list comprehensions, and real‑world examples with complete code snippets.
LoopsTutorialfor loop
0 likes · 7 min read

This article explains Python's core control‑flow constructs—if‑elif‑else, while, and for loops—providing clear explanations, runnable code examples, and additional notes on boolean logic and string formatting for beginners and intermediate programmers.
Pythoncontrol flowfor loop
0 likes · 4 min read

This article compares the performance of common JavaScript looping constructs—including for, reverse for, forEach, for...of, for...in, and for...await—provides benchmark code on a million‑element array, explains the speed differences, and offers guidance on choosing the right loop for readability and maintainability.
JavaScriptLoopsbenchmark
0 likes · 7 min read

This tutorial demonstrates three ways to calculate the average of an integer array—using a classic Java for‑loop, a Java Stream Lambda expression, and Groovy’s built‑in collection methods—complete with code samples and console output.
Array averageGroovyJava
0 likes · 5 min read

This article explains why Python lacks the ++/-- increment operators, covering the immutable nature of Python integers and how its powerful iterable constructs provide a cleaner alternative for iteration and value updates.
Pythonfor loopimmutable integers
0 likes · 8 min read

This article compares the two common ways to write infinite loops in Java—while(true) and for(;;)—exploring their origins, usage differences, and performance by examining JDK source counts and compiled bytecode, concluding they are functionally equivalent.
Javafor loopinfinite loop
0 likes · 5 min read

This article explains why removing items from a Java List inside a foreach loop triggers java.util.ConcurrentModificationException and demonstrates three reliable alternatives—using Iterator.remove(), a forward for‑loop with index adjustment, and a reverse for‑loop—to safely modify collections during iteration.
ConcurrentModificationExceptionJavafor loop
0 likes · 7 min read

During a Java interview, a common mistake of using a foreach loop to remove elements from an ArrayList triggers a ConcurrentModificationException; this article explains the underlying iterator mechanism, shows the bytecode behavior, and presents four safe alternatives—including iterator.remove(), forward and backward for-loops—to avoid the error.
ConcurrentModificationExceptionJavaarraylist
0 likes · 7 min read

This article explains why removing items from a Java List inside a foreach loop triggers a ConcurrentModificationException and demonstrates three correct approaches—using Iterator.remove(), a forward indexed for loop with index correction, and a reverse for loop—each with full code examples and output.
ConcurrentModificationExceptionJavaarraylist
0 likes · 6 min read


ITPUBFeb 21, 2020 · Fundamentals
This article explains how Python’s for loops work, introduces list comprehensions as a concise alternative, compares their performance and readability, and provides numerous code examples—including dictionary, set, and multi‑loop comprehensions with conditional logic—to help developers write clearer, more efficient code.
Code Examplesfor looplist comprehension
0 likes · 8 min read

This guide shows how to use Unix shell for‑loops and the find command to batch‑process files, resize images with ImageMagick, limit iterations, handle numeric loops, and adapt the syntax for different shells, providing practical examples and complete command snippets.
ImageMagickfindfor loop
0 likes · 11 min read

This article explores why Python’s for‑loop index variables remain visible after the loop, examines the underlying bytecode and AST handling, and explains why this behavior persists and can be useful in real‑world code.
ASTPythonVariable Scope
0 likes · 11 min read

The article explains that the infinite loop constructs for(;;) and while(true) in Java originate from C, discusses their syntax and usage, and shows through bytecode inspection that both compile to identical instructions, resulting in no measurable performance gap.
for looplanguage fundamentalswhile-loop
0 likes · 4 min read

This guide explains Python’s built‑in enumerate() function, covering its purpose, syntax, parameters, return type, and practical examples with lists, tuples, strings, dictionaries and sets to help you iterate with automatic indexing in for‑loops.
IndexingPythonenumerate
0 likes · 4 min read

This article challenges the habit of writing for loops in Python, explains the intuition behind them, outlines the benefits of avoiding them, and demonstrates practical alternatives such as list comprehensions, generator expressions, map, reduce, functions, and itertools with clear code examples.
Pythoncode optimizationfor loop
0 likes · 8 min read

This article provides a comprehensive guide to Linux shell flow‑control constructs, covering conditional statements (if/elif/else), loops (for, while, until), and selection statements (case, select), complete with syntax explanations, practical examples, and execution results to help readers master shell scripting.
Case statementFlow Controlfor loop
0 likes · 6 min read

This guide demonstrates how to define a Python list, print its contents, and iterate over each element using both a for‑loop and a while‑loop, including step‑by‑step code explanations and common pitfalls such as infinite loops and type conversion.
ListLoopsPython
0 likes · 4 min read

This concise guide explains how Python supports nesting loops, shows the exact syntax for embedding for‑loops inside while‑loops and vice versa, and provides a complete example that prints all prime numbers between 2 and 100, complete with output screenshots.
Prime NumbersPythonfor loop
0 likes · 2 min read

This article introduces Python's loop constructs, detailing the differences between for and while loops, how to nest loops, and the use of control statements like break, continue, and pass to manage loop execution flow.
Loopscontrol statementsfor loop
0 likes · 3 min read


21CTOFeb 9, 2016 · Frontend Development
This article explains how replacing traditional for‑loops with JavaScript’s map method leads to more declarative, readable code, reduces boilerplate, improves maintainability, and offers comparable performance, while also discussing functional programming principles, browser support, and best practices for naming helper functions.
JavaScriptdeclarative programmingfor loop
0 likes · 7 min read
