Skip to content

Commit

Permalink
JS Do While Loop
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzalodhi2023 committed Nov 4, 2023
1 parent de0a5ba commit 85eb40f
Show file tree
Hide file tree
Showing 2 changed files with 313 additions and 0 deletions.
310 changes: 310 additions & 0 deletions JS-Do-While-Loop.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,310 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JS Do While Loop</title>
<style>
* {
font-family: Arial, Helvetica, sans-serif;
}

table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 50%;
}

td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}

tr:nth-child(even) {
background-color: #dddddd;
}

code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
background-color: rgba(0, 0, 0, 0);
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
font-size: 1em;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

:not(pre) > code[class*="language-"]::after,
pre[class*="language-"]::after {
right: 0.75em;

left: auto;

-webkit-transform: rotate(2deg);

-moz-transform: rotate(2deg);

-ms-transform: rotate(2deg);

-o-transform: rotate(2deg);

transform: rotate(2deg);
}
pre[class*="language-"]::before,
pre[class*="language-"]::after {
content: "";

z-index: -2;

display: block;

position: absolute;

bottom: 0.75em;

left: 0.18em;

width: 40%;

height: 20%;

max-height: 13em;

-webkit-transform: rotate(-2deg);

-moz-transform: rotate(-2deg);

-ms-transform: rotate(-2deg);

-o-transform: rotate(-2deg);

transform: rotate(-2deg);
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background-color: #fdfdfd;

-webkit-box-sizing: border-box;

-moz-box-sizing: border-box;

box-sizing: border-box;

margin-bottom: 1em;
}
pre[class*="language-"] {
position: relative;

margin: 0.5em 0;

margin-bottom: 0.5em;

overflow: visible;

padding: 0;
}
code[class*="language-"],
pre[class*="language-"] {
color: black;

background: none;

background-color: rgba(0, 0, 0, 0);

font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;

font-size: 1em;

text-align: left;

white-space: pre;

word-spacing: normal;

word-break: normal;

word-wrap: normal;

line-height: 1.5;

-moz-tab-size: 4;

-o-tab-size: 4;

tab-size: 4;

-webkit-hyphens: none;

-moz-hyphens: none;

-ms-hyphens: none;

hyphens: none;
}
pre {
display: block;

font-size: 87.5%;

color: #212529;
}
pre {
margin-top: 0;

margin-bottom: 1rem;

overflow: auto;

-ms-overflow-style: scrollbar;
}
code,
kbd,
pre,
samp {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
"Courier New", monospace;

font-size: 1em;
}

pre[class*="language-"] > code {
position: relative;
border-left: 10px solid #358ccb;
box-shadow: -1px 0px 0px 0px #358ccb, 0px 0px 0px 1px #dfdfdf;
background-color: #fdfdfd;
background-image: linear-gradient(
transparent 50%,
rgba(69, 142, 209, 0.04) 50%
);
background-size: 3em 3em;
background-origin: content-box;
background-attachment: local;
}

code[class*="language"] {
max-height: inherit;
height: inherit;
padding: 0 1em;
display: block;
overflow: auto;
}

code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
background-color: rgba(0, 0, 0, 0);
background-attachment: scroll;
background-image: none;
background-size: auto;
background-origin: padding-box;
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
font-size: 1em;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

pre code {
font-size: inherit;
color: inherit;
word-break: normal;
}

code {
font-size: 87.5%;
color: #e83e8c;
word-wrap: break-word;
}
code,
kbd,
pre,
samp {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
"Courier New", monospace;
font-size: 1em;
}
*,
::after,
::before {
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>JS Do While Loop</h1>
<p>
A do… while loop in JavaScript is a control statement in which the code is
allowed to execute continuously based on a given boolean condition. It is
like a repeating if statement.
</p>
<p>
The do…while loop can be used to execute a specific block of code at least
once.
</p>
<h3>Syntax:</h3>
<pre
class="language-javascript"
tabindex="0"
><code class="language-javascript"><span class="token keyword">do</span> <span class="token punctuation">{</span>
<span class="token comment">// Statements</span>
<span class="token punctuation">}</span>
<span class="token keyword">while</span><span class="token punctuation">(</span>conditions<span class="token punctuation">)</span></code></pre>
<p>
The main difference between do…while and while loop is that it is
guaranteed that do…while loop will run at least once. Whereas, the while
loop will not run even once if the given condition is not satisfied.
</p>
<pre
class="language-markup"
tabindex="0"
><code class="language-markup"><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>JavaScript<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">do</span><span class="token punctuation">{</span>
document<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>a <span class="token operator">+</span> <span class="token string">" Hello Yahoo Baba&lt;br&gt;"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
a<span class="token operator">++</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token keyword">while</span><span class="token punctuation">(</span>a <span class="token operator">&lt;=</span> <span class="token number">10</span><span class="token punctuation">)</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre>
</body>
<script>
let a = 50000;
do {
document.write(a + "). " + "HELLO SIR.<br>");
a = a - 1;
} while (a >= 1);
</script>
</html>
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ <h1>JS NOTES</h1>
<li>
<a href="JS-While-Loop.html">JS While Loop</a>
</li>
<li>
<a href="JS-Do-While-Loop.html">JS Do While Loop</a>
</li>
</ol>
</body>
</html>

0 comments on commit 85eb40f

Please sign in to comment.