Logic behind geometric shapes- diamonds

So I've found this piece of code but I'm having a hard time understanding how it works. Could someone please help me to understand this code? I want to make a diamond of my own but have no idea how to get started.


Diamond Code

#include <iostream>

void main() {
const int N=5;

for (int i = 0; i <= 2 * N; i++) {
for (int j = 0; j <= 2 * N; j++) {
if (i <= N) {
if (j < N - i || j > N + i) {
std::cout << ' ';
}
else {
std::cout << '*';
}
}
else {
if (j < i - N || j > 3 * N - i) {
std::cout << ' ';
}
else {
std::cout << '*';
}
}
}
std::cout << std::endl;
}
}
Topic archived. No new replies allowed.