Skip to content

Commit

Permalink
Add weird loops
Browse files Browse the repository at this point in the history
Signed-off-by: 0x4248 <60709927+0x4248@users.noreply.github.com>
  • Loading branch information
0x4248 committed Nov 23, 2024
1 parent 8db3d8e commit 190d73d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
16 changes: 16 additions & 0 deletions c/weird_loops/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: GPL-3.0
# weird_loops
#
# CMakeLists.txt
#
# COPYRIGHT NOTICE
# Copyright (C) 2024 0x4248 and contributors
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the license is not changed.
#
# This software is free and open source. Licensed under the GNU general
# public license version 3.0 as published by the Free Software Foundation.

project(weird_loops)

add_executable(main main.c)
73 changes: 73 additions & 0 deletions c/weird_loops/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* SPDX-License-Identifier: GPL-3.0
* weird_loops
*
* main.c
*
* Looping in a weird way
*
* COPYRIGHT NOTICE
* Copyright (C) 2024 0x4248 and contributors
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the license is not changed.
*
* This software is free and open source. Licensed under the GNU general
* public license version 3.0 as published by the Free Software Foundation.
*/

#include <stdio.h>
#include <stdlib.h>

int jumps(){
int i = 0;
loop:
if (i < 10) {
printf("i = %d\n", i);
i++;
goto loop;
}
return 0;
}

int while_loop() {
int i = 0;
while (i < 10) {
printf("i = %d\n", i);
i++;
}
return 0;
}

int normal_loop() {
for (int i = 0; i < 10; i++) {
printf("i = %d\n", i);
}
return 0;
}

int do_while_loop() {
int i = 0;
do {
printf("i = %d\n", i);
i++;
} while (i < 10);
return 0;
}

int main() {

printf("Normal loop\n");
normal_loop();
printf("\n");

printf("While loop\n");
while_loop();
printf("\n");

printf("Do while loop\n");
do_while_loop();
printf("\n");

printf("Jump loop\n");
jumps();
printf("\n");
}
3 changes: 2 additions & 1 deletion scraps.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ MK-S += !c/writing_raw
MK-S += !c/http_server
MK-S += @c/tiny/build.sh
MK-S += !c/factorial
MK-S += !c/XORenc
MK-S += !c/XORenc
MK-S += !c/weird_loops

0 comments on commit 190d73d

Please sign in to comment.