《Programming Wizards!》Gyroplane
Advertisement
“A friend of mine returned from an expedition yesterday.” The students attentively listened, for stories from beyond Rorohiko were rare. “They flew over a forest in a gyroplane.” He looked around. “Does anyone know what a gyroplane is?” He pointed to a student with his hand raised.
“A vehicle capable of flying in any direction or hovering in place using its propellers.”
“Yes, what is your name?”
“Roy.”
“Roy, do you know how we can keep its propellers turning?”
He thought for a moment, then shrugged. “I’m not sure what you mean.”
“How can we run code repeatedly?”
He thought some more. “Wouldn’t you have to keep executing the code again and again?”
“Yes, do you know how to write that in code?”
“No, unless you’re about to teach us how to do it at runtime.”
Vick smiled, he knew this class was different. “Yes. Today, you will learn how.”
while (true) { Console.WriteLine(“Looped!”); }
“Above me,” he pointed to the screen, “is a ‘while loop.’” He executed the code. ‘Looped!’ it said. Then, on the line under it: ‘Looped!’ Then, on the line under that: ‘Looped!’ Then, over and over and over. “It will continue to execute as long as its condition is true. What we’ve created is an infinite loop.”
int i = 0; while (i < 5) { i = i + 1; Console.WriteLine(“Loop #” + i); }
He ran the code, and after displaying five lines, ‘Loop #1,’ ‘Loop #2…’ the program completed its execution. “The condition is checked before the execution of the loop. The loop is only executed if the condition is true. What we’ve made is essentially a ‘for loop.’”
Advertisement
for (int i = 0; i < 5; i = i + 1) { Console.WriteLine(“Loop #” + (i + 1)); }
He ran the code again, and it displayed the same five lines. “Instead of declaring an integer beforehand, and incrementing it in the loop, we can declare it, condition it, and increment it in a single line. That’s the power of a for loop. Note how we add one to the variable ‘i’ before concatenating it. This is because, in a for loop, the increment occurs after the loop’s execution. Whereas, before we incremented ‘i’ at the start of the loop.”
do { Console.WriteLine(“Looped!”); } while (true);
“The last loop is similar to a while loop,” he raised a finger, “with one important distinction. It executes at least once. Meaning, it executes once, then evaluates the condition to figure out if it should execute again. This is a ‘do while loop.’ Or simply, ‘do loop.’” He looked over the class, looking each student in the eye. “If you are to become apprentices, you must be wary with your use of loops.” His voice was uncomfortably firm, almost grim. “We will entrust you with precious resources, if you accidentally make an infinite loop where resources are expunged, there will be grave consequences.” He diverted his attention back to the computer. “Now, what does this have to do with gyroplanes? Well, their propellers need constant energy to spin.”
bool isOn = true; while (isOn) { Console.WriteLine(“Spin!”); }
‘Spin!’ said the screen over and over. “Yes, it is an infinite loop. However, another process would be occurring between each loop. That process would detect if a button was pressed which toggles the boolean. When that button is pressed, the loop will evaluate its condition as false, stopping it.”
Advertisement
for (float speed = 1f; speed < 20f; speed += 2f) { Console.WriteLine(“Spinning at speed: ” + speed); }
“The ‘f’ letter at the end of the numbers is to indicate it as a float in this language, not to be confused for an integer. The speed of the propeller can be controlled with each execution of the loop. Begins at one, only executes if it’s below twenty, increments by two every loop.” He walked closer to the class and stood taller. “Because of our great wizards, we were able to construct hardware that made it impossible for a propeller to spin too fast. So, even if we made an error where the speed became an enormous number, the propeller would simply rotate at its max speed dictated by its hardware. Just as integers and floats have a min and max range, so does the speed of a propeller. Zero being its min, and around four-hundred being its max.”
“What does ‘speed += 2f’ mean?” asked Willard.
“That’s shorthand for incrementing by two, and then setting that value to the variable.”
After class, the three huddled to converse. “Hey,” said Willard. “Does anyone know what a forest is? I heard Mister Vick use that word.”
“I’m not sure,” said Andrew, and Gus shrugged.
“It’s a massive cluster of trees,” said Roy, from down the hall, and walked towards them.
“Like, five or so?” asked Willard.
“No,” said Roy and stretched his arms to his sides. “A thousand kilometers, maybe more.”
Everyones’ jaw dropped. “What?” said Gus.
“A thousand kilometers? That’s impressive,” said Andrew.
Advertisement
-
In Serial9 Chapters
RE: Monarch
Cairn is a prince who is already tired of ruling. Faced with an imminent coronation and an overbearing father, he wants nothing more than to drown his responsibilities in cheap liquor and poor decisions. With the help of his sister, he hatches a plan to escape the clutches of the throne once and for all. It all goes terribly wrong, and Cairn finds his priorities shifting in the face of unimaginable tragedy. The change of heart comes too late, however, and Cairn dies. He reawakens to find himself transported ten years in the past. He immediately begins to plan for the future, only to discover his killer has somehow followed him. To succeed, Cairn must unite the kingdom and discover the motivation of his killer, using as many tries as it takes. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ I exhausted pretty much every time loop story ever written and decided to write my own. You'll see a few similarities here between this story and some existing stories, at least initially. There's a lot of inspiration drawn from both MoL and Re:Zero, though in terms of pathos and darkness, this story leans more towards the latter. Be warned, it is something of a slow burn. The main character will grow and become powerful, but a theme of this story is that power comes slowly and often at great cost. Book One: Kindle Edition and Audiobook Developmental Editing by the all seeing Irock4691
8 265 -
In Serial248 Chapters
Rebirth: Monarchs
[A rewrite of a previous series: Rebirth: Hero!] Description: As he grows, the world trembles; as he speaks, the world listens; what he wills, the world provides; common sense overturned by his power. A man is reborn from a previous life into a human, the weakest race on the planet. Along with him, a girl whom he saved in his last moments. With the memories of Kai’s past and present life, can he conquer everything and truly be a Monarch? Together with the residents of the new world, watch as they pierce through the boundaries and break through the chains of fate! [Updated description] Summary: Kai dies trying to save a girl and is reborn as a human in another world, the being who reincarnated him and the girl he saved gave him the task of becoming a monarch which he made his goal along with meeting the girl he saved once more.
8 206 -
In Serial8 Chapters
Monstrous Intentions
Life is hard. Horrible monsters lurk around every corner, waiting for the right time to strike. It’s a good thing the world is overflowing with adventurers who dedicate their lives to hunting monsters down and killing them with impunity. Unless of course, you are one such monster. When survival depends on blending in, it's best not to cause any trouble. Too bad sometimes trouble finds you. The story of a shapeshifting monster doing its best to hide in plain sight. Updates Fridays, Sometimes Tuesdays if I'm not lazy.
8 148 -
In Serial6 Chapters
Reborn as Kurama: applying scientific method
Reborn in Narutoverse as Kurama, reincarnated scientist wants 2 things - power to keep himself free from enslavement and to built liberal oligarchy, will he get what he wants?)
8 125 -
In Serial27 Chapters
Shifted
After the world is almost entirely overrun by a mysterious force known only as the Spread, individual cities struggle to survive behind Barriers with limited resources under the direct supervision of the richest among them. Accidentally overhearing a plot by his city's leader to doom a large swathe of the population, Lysander Badeaux concocts a last ditch slapdash plan to save them. Enlisting the help of the city's most feared assassin, the Red Morn, he sets out to fix what's broken, only to stumble upon more than he bargained for in the process. With Red keeping a host of secrets from him--and not to mention following him around for some inexplicable reason--Lysander may just bumble his way into a conspiracy or a magic world or, if he's excessively unlucky (and he is), both. Note: First time posting here or any original fiction, in general. Please feel free to give any feedback you like! Much love and thanks for reading. Posts every week (gods willing).
8 176 -
In Serial18 Chapters
Stress Relief (Grizz x Nom Nom)
As soon as Nom Nom returns from vacation he is bombarded with his fans left waiting. With the risks of his stress getting out of hand he no choice but to stay with Grizz off the grid in the forrest. While there he comes to realize things not only about himself but about others who he might come to care about.
8 75
